import axios from "axios"

axios.defaults.baseURL = "http://127.0.0.1:3007"

let loadingInstance = null

// 配置请求拦截器
axios.interceptors.request.use(
  (config) => {
    // 配置token
    // if (localStorage.getItem("token")) config.headers.Authorization = localStorage.getItem("token")
    // 展示loading
    loadingInstance = ElLoading.service({ fullscreen: false, lock: true, text: "加载中..." })
    return config
  },
  (err) => Promise.reject(err),
)

// 配置响应拦截器
axios.interceptors.response.use((res) => {
  // 关闭loading
  loadingInstance.close()
  return res
})

export default axios
